home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  767 b   |  37 lines

  1. #include "lib.h"
  2.  
  3. /*
  4.  * strstr - find first occurrence of wanted in s
  5.  */
  6. #ifdef NULL
  7. #undef NULL
  8. #endif
  9.  
  10. #define    NULL    0
  11.  
  12. char *                /* found string, or NULL if none */
  13. strstr(s, wanted)
  14. _CONST char *s;
  15. _CONST char *wanted;
  16. {
  17.     register _CONST char *scan;
  18.     register _SIZET len;
  19.     register char firstc;
  20. #ifndef __STDC__    /* for __STDC__ pick up proto from <std.h> */
  21.     extern int strcmp();
  22.     extern _SIZET strlen();
  23. #endif
  24.  
  25.     /*
  26.      * The odd placement of the two tests is so "" is findable.
  27.      * Also, we inline the first char for speed.
  28.      * The ++ on scan has been moved down for optimization.
  29.      */
  30.     firstc = *wanted;
  31.     len = strlen(wanted);
  32.     for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
  33.         if (*scan++ == '\0')
  34.             return(NULL);
  35.     return((char *)scan);
  36. }
  37.